package com.ruowei.modules.sys.utils;

import org.apache.commons.math3.random.RandomDataGenerator;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public final class CIS003Util {

    public static String genRequest(String IdentNbr, String AcctNm) {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dateDTF = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter timeDTF = DateTimeFormatter.ofPattern("hh.mm.ss");
        RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
        // @formatter:off
        String body =
            "<CBSSTDREQ>" +
                "<InfTp>RQ</InfTp>" +
                "<SvcCd>CIS003</SvcCd>" +
                "<BsnTxDt>" + dateDTF.format(now) + "</BsnTxDt>" +
                "<SysDt>" + dateDTF.format(now) + "</SysDt>" +
                "<SysTm>" + timeDTF.format(now) + "</SysTm>" +
                "<BrNbr>01101</BrNbr>" +
                "<SecFlg>0</SecFlg>" +
                "<TlrNbr>888888</TlrNbr>" +
                "<TxFlg>0</TxFlg>" +
                "<TxSeqNbr>00000000</TxSeqNbr>" +
                "<AuthInfFlg>0</AuthInfFlg>" +
                "<InptWordFlg>0</InptWordFlg>" +
                "<SignInfFlg>0</SignInfFlg>" +
                "<RmtAhrAplFlg>0</RmtAhrAplFlg>" +
                "<ChkTlrNbr>000000    </ChkTlrNbr>" +
                "<BranchTmlNbr>          </BranchTmlNbr>" +
                "<UpldFldNmLen>0000</UpldFldNmLen>" +
                "<UpldFldSecVal>        </UpldFldSecVal>" +
                "<SgnFld>00000000000000000000000000000000000000000000000000000000000</SgnFld>" +
                "<CnlCd>N6</CnlCd>" +
                "<EqmtTpCd></EqmtTpCd>" +
                "<PtTxCd>" + randomDataGenerator.nextSecureHexString(10) + "</PtTxCd>" +
                "<PtTxDt>" + dateDTF.format(now) + "</PtTxDt>" +
                "<PtTxTm>" + timeDTF.format(now) + "</PtTxTm>" +
                "<PtSeqNbr>" + randomDataGenerator.nextSecureHexString(8) + "</PtSeqNbr>" +
                "<ExprTxCd>" + randomDataGenerator.nextSecureHexString(10) + "</ExprTxCd>" +
                "<ExprDt>" + dateDTF.format(now) + "</ExprDt>" +
                "<ExprTm>" + timeDTF.format(now) + "</ExprTm>" +
                "<ExprSeqNbr>" + randomDataGenerator.nextSecureHexString(8) + "</ExprSeqNbr>" +
                "<ReqIP>10.1.57.99</ReqIP>" +
                "<TmlNbr></TmlNbr>" +
                "<SvcPblcCtlrTp>11111     </SvcPblcCtlrTp>" +
                "<SvcInptCtrlTp>000000  1101 10     </SvcInptCtrlTp>" +
                "</CBSSTDREQ>" +
                "<QryTp>3</QryTp>" +
                "<IdentNbr>" + IdentNbr + "</IdentNbr>" +
                "<AcctNm>" + AcctNm + "</AcctNm>";
        // @formatter:on
        return ESBUtil.genRequest("CBS.00CIS0030.01", body);
    }
}
